<template>
  <el-dialog
  title="提示"
  :visible.sync="dialogVisible"
  width="30%"
  :before-close="handleClose">
  
  <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
    <el-form-item label="信息" prop="info">
    <el-input v-model="ruleForm.info"></el-input>
    </el-form-item>
    <el-form-item label="报名费" prop="money">
            <el-input v-model.number="ruleForm.money"></el-input>
        </el-form-item>  
         <el-form-item label="销量" prop="sale">
            <el-input v-model.number="ruleForm.sale"></el-input>
        </el-form-item> 
         <el-form-item label="上传人" prop="name">
            <el-input v-model.number="ruleForm.name"></el-input>
        </el-form-item> 
</el-form>

  <span slot="footer" class="dialog-footer">
    <el-button  @click='closedialog'>取 消</el-button>
    <el-button type="primary"     @click="submitForm('ruleForm')">提 交</el-button>
  </span>
</el-dialog>
</template>

<script>
import { updateFunApi } from '../../../api/studentApi'
export default {
    props:['arr'],
     data() {
      return {
        dialogVisible: true,
         ruleForm: {
          name:'',
          money:'',
          sale:'', 
          info: '',
        },
         rules: {
          info: [ 
            { required: true, message: '请输入信息', trigger: 'blur' },//判空
          ],
          money: [ 
            { required: true, message: '请输入价格', trigger: 'blur' },//判空
          ],
          sale: [
            { required: true, message: '请输入销量', trigger: 'blur' }//判空
          ],
          name: [
            { required: true, message: '请输入用户姓名', trigger: 'blur' },//判空
          ],
          }
      };
    },
   mounted(){
        this.ruleForm = {...this.arr} //一层对象， 解构赋值是可以的  JSON.parse(JSON.stringify())
    },
    methods: {
        submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
              console.log('this.ruleForm',this.ruleForm);
                updateFunApi(this.ruleForm).then(res=>{
                  console.log(res);
                    if(res.code == 200){
                        this.$emit('resettable')
                    }
                })

          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
        closedialog(){
            this.$emit('closedialog')
        },

      handleClose(done) {
        this.$confirm('确认关闭？')
          .then(_ => {
            done();
            this.$emit('closedialog')
          })
          .catch(_ => {});
      }
    }
  }
</script>

<style>

</style>